package com.aaa.day02.myclass;

import java.util.Random;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2024/11/12 14:19
 * @description：学生类
 * @modified By：
 * @version: 1.0
 */
public class Student   {
      int  id;
      String  name;
      int age;
      public void introduce(){
          System.out.println("我是："+name+"学号是："+id+"年龄："+age);
      }
      public  void study(){
          System.out.println("学习");
      }
      public  void code(){
          System.out.println("编码");
      }

    public Student(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public Student() {
    }

    public static void main(String[] args) {
       /*   //实例化一个对象，空对象,
        Student student=new Student();
        //给空对象赋值
        student.id=9527;
        student.name="华安";
        student.age=30;
        student.introduce();*/
        //循环创建五个学生
        Student[] students=new Student[5];
        for (int i = 0; i < students.length; i++) {
            //获取100以内的随机数
            Random random = new Random();
            int age = random.nextInt(100)+1;
            Student student=new Student(i,"学生"+i,age);
            students[i]=student;
        }
        //打印所有的学生信息
        for (Student student : students) {
           student.introduce();
        }
        //判断最大的年龄和最小的年龄
        int maxAge=0;
        Student studentMaxAge = new Student();
        Student studentMinAge=new Student();
        int minAge=Integer.MAX_VALUE;
        int sum=0;
        for (int i = 0; i < students.length; i++) {
            if(maxAge<students[i].age){
                maxAge=students[i].age;
               studentMaxAge=students[i];
            }
            if(minAge>students[i].age){
                minAge=students[i].age;
                studentMinAge=students[i];
            }
            sum+=students[i].age;
        }
        System.out.println("===============================");
        System.out.print("最大年龄：");
        studentMaxAge.introduce();
        System.out.print("最小年龄：");
        studentMinAge.introduce();
        System.out.println("平均年龄："+sum/students.length);
        //跨类访问属性
       /* MyStaticTest myStaticTest= new MyStaticTest();
        myStaticTest.id=4324;*/
       /* MyStaticTest.id=5432543;*/
    }
}
